<template>
    <base-breadcrumb>
        <searchData :searchData="searchArr" @search="search"></searchData>
        <a-card>
            <div class="table-operator">
                <a-button type="primary" icon="plus" @click="handleUpdate('add')" v-btnPermission="'hse_012_add_01'"
                    >新增</a-button
                >
            </div>
            <s-table
                ref="table"
                size="default"
                rowKey="key"
                :columns="columns"
                :data="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
            >
                <span slot="sort" slot-scope="text, record, index">{{ index + 1 }}</span>
                <span slot="action" slot-scope="text, record">
                    <a @click="handleUpdate('look', record)" v-btnPermission="'hse_012_loo_04'">查看</a>
                    <a-divider type="vertical" v-btnPermission="'hse_012_loo_04'" />
                    <a @click="handleUpdate('edit', record)" v-btnPermission="'hse_012_edi_02'">编辑</a>
                </span>
                <span slot="auditStatus" slot-scope="text">
                    <list-status status="SUBMITTED" conversion="en" :text="text"></list-status>
                </span>
            </s-table>
        </a-card>
    </base-breadcrumb>
</template>
<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { STable } from '@/components'
import { getSecurityLogPlanList } from '@/api/safetySupervision/securityLog'
const columns = [
    {
        title: '序号',
        dataIndex: 'sort',
        scopedSlots: { customRender: 'sort' },
    },
    {
        title: '所属分公司',
        dataIndex: 'branchComName',
    },
    {
        title: '所属项目',
        dataIndex: 'projectName',
    },
    {
        title: '日期',
        dataIndex: 'logTime',
    },
    {
        title: '状态',
        dataIndex: 'auditStatus',
        scopedSlots: { customRender: 'auditStatus' },
    },
    {
        title: '操作',
        dataIndex: 'action',
        width: '170px',
        scopedSlots: { customRender: 'action' },
    },
]
const searchArr = [
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany,
    // },
    {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject,
    // },
    {
        name: '填报时间',
        value: 'applyTime',
        type: 'dateRange',
    },
    // {
    //     name: '状态',
    //     value: 'auditStatus',
    //     type: 'select',
    //     data: [
    //         {
    //             value: '0',
    //             label: '未提交  ',
    //         },
    //         {
    //             value: '1',
    //             label: '已提交',
    //         },
    //     ],
    // },
]
export default {
    name:'a'+Date.now(),    components: {
        STable,
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            queryParam: {},
            loadData: async (parameter) => {
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                const [err, res] = await getSecurityLogPlanList(requestParameters)
                return new Promise((resolve, reject) => {
                    if (err) {
                        reject(err)
                    } else {
                        resolve(res)
                    }
                })
            },
        }
    },
    methods: {
        //搜索
        search(val = {}) {
            const year = new Date().getFullYear()
            this.queryParam = {
                ...val,

                beginTime:
                    (val.applyTime && val.applyTime.length && val.applyTime[0].format('YYYY-MM-DD HH:mm:ss')) || void 0,
                endTime:
                    (val.applyTime && val.applyTime.length && val.applyTime[1].format('YYYY-MM-DD HH:mm:ss')) || void 0,
            }

            this.$refs.table.refresh(true)
        },
        // 处理更新操作（新增、编辑）
        handleUpdate(type, data = {}) {
            let path = ''
            if (type == 'look') {
                path = 'checkSecurityLog'
            } else {
                path = 'addSecurityLog'
            }
            this.$router.push({
                name: path,
                query: {
                    id: data.id || '',
                    pageType: type,
                },
            })
        },
    },
}
</script>
